package com.jd.platform.hotkey.worker.config;

import com.jd.platform.hotkey.common.configcenter.IConfigCenter;
import com.jd.platform.hotkey.common.configcenter.etcd.JdEtcdBuilder;
import com.jd.platform.hotkey.worker.netty.pusher.RocketMqPusher;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author wuweifeng wrote on 2019-12-06
 * @version 1.0
 */
@Configuration
public class RocketMQConfig {
    @Value("${rocketmq.hosts}")
    private String hosts;
    @Value("${rocketmq.hotkey.topic}")
    private String topic;
    @Value("${rocketmq.hotkey.groupName}")
    private String groupName;


    @Bean
    public RocketMqPusher.MqSender mqSender() {

        DefaultMQProducer producer = new DefaultMQProducer(groupName);
        producer.setNamesrvAddr(this.hosts);
        try {
            producer.start();
        } catch (MQClientException e) {
            throw new RuntimeException(e);
        }
        //连接多个时，逗号分隔
        return new RocketMqPusher.MqSender(producer, topic);
    }

}
